﻿<%@ Page Title="" Language="C#" MasterPageFile="~/admin/admin.master" AutoEventWireup="true" CodeFile="add.aspx.cs" Inherits="admin_resources_add" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <link href="../artcles/StyleSheet.css" type="text/css" rel="Stylesheet" />
    <script type="text/javascript" src="../../js/jquery-1.4.1.min.js"></script>
    <script type="text/javascript" src="../../js/xheditor-1.1.13-zh-cn.min.js"></script>
    <script type="text/javascript" src="../../js/jquery-ui.min.js"></script>
    <script type="text/javascript" src="../../js/base.js"></script>
    <script src="../../js/uploadify-v2.1.4/jquery.uploadify.v2.1.4.min.js" type="text/javascript"></script>
    <script src="../../js/uploadify-v2.1.4/swfobject.js" type="text/javascript"></script>
    <link href="../../js/uploadify-v2.1.4/uploadify.css" rel="Stylesheet" />
    <script type="text/javascript">
        var chooseclassid;
        var resid;
        var editor;
        $(document).ready(function () {
            var act = getQueryString("act");
            $("#uploadify").uploadify({
                'uploader': '../../js/uploadify-v2.1.4/uploadify.swf', //进度条，Uploadify里面含有 
                'script': '../../Handles/file/upload.ashx', //一般处理程序 
                'cancelImg': 'jquery.uploadify-v2.1.4/cancel.png', //取消图片路径 
                'folder': '../../upload/files', //上传文件夹名 
                'queueID': 'fileQueue',
                'auto': false,
                'onComplete': function (event, queueID, fileObj, response, data) {
                    //alert(response+";"+queueID+";"+fileObj.name+";"+data.speed);
                    $("#comfile").append('<p>' + fileObj.name + '&nbsp&nbsp<span style="color:red">complete!</span></p>');
                    AddAtt(response, fileObj);
                },
                'multi': false,
                'sizeLimit': 10737418240
            });
            InitClassList();
            $("#savebtn").click(function () {
                if (chooseclassid == undefined) {
                    if (!confirm("未选择分类，是否继续？")) {
                        return false;
                    }
                }
                SaveRes();
            });
            if (act == "edit") {
                GetRes();
                $("#publicbtn").hide();
            }
            $("#showupload").click(function () {
                if (resid == undefined || resid == 0) {
                    alert("请先保存分类");
                }
                else {
                    $(this).hide();
                    $("#fileupload").show();
                }
            });
        });
        function InitClassList() {
            var postdata = { "act": "get" };
            $.ajax({
                url: "../../Handles/resource/resclass.ashx",
                type: "POST",
                datatype: "xml",
                data: $.param(postdata),
                success: function (xml) {
                    classlistxml = xml;
                    $("#ClassList").empty();
                    $(xml).find("Table").each(function (v) {
                        var classid = $(this).attr("ClassID");
                        var cname = $(this).children("ClassName").text();
                        var html = '<p><input type="radio" name="resclass" class="resclasslist" ';
                        html += 'value="' + classid + ' " />';
                        html += '<span>' + cname + '</span';
                        html += '</p>';
                        $("#ClassList").append(html);
                        $(".resclasslist").click(function () {
                            chooseclassid = $(this).attr("value");
                        });
                    });
                }
            });
        }
        function SaveRes() {
            if (resid == undefined) {
                var senddata = { "act": "save", "title": $("#titlebox").val(), "content": editor.html(), "classid": chooseclassid};
                $.ajax({
                    url: "../../Handles/resource/ResHandler.ashx",
                    type: "post",
                    data: $.param(senddata),
                    success: function (data) {
                        alert(data);
                    }
                });
            }else {
            var senddata = { "act": "update", "title": $("#titlebox").val(), "content": editor.html(), "classid": chooseclassid,"resid":resid };
                $.ajax({
                    url: "../../Handles/resource/ResHandler.ashx",
                    type:"post",
                    data: $.param(senddata),
                    success: function (data) {
                        if(data !==0){
                            resid=data;
                        }
                        else{
                            alert("保存错误！");
                        }
                    }
                });
            }
        }
        function GetRes() { 
            resid = getQueryString("resid");
            var senddata = { "act": "getres", "resid": resid };
            $.ajax({
                url: "../../Handles/resource/ResHandler.ashx",
                type: "post",
                datatype: "json",
                data: $.param(senddata),
                success: function (data) {
                    $("#titlebox").val(data.Title);
                    editor.html(data.Content);
                    chooseclassid = data.ClassID;
                    $(".resclasslist").each(function () {
                        if ($(this).attr("value") == chooseclassid) {
                            $(this).attr("checked", "checked");
                        }
                    });
                }
            });
        }
        function AddAtt(fileurl,fileObj) {
            var senddata = { "size": fileObj.size, "resid": resid, "fileurl": fileurl, "filename": fileObj.name };
            $.ajax({
                url: "../../Handles/resource/ResHandler.ashx",
                type: "post",
                datatype: "json",
                data: $.param(senddata),
                success: function (data) {
                    if (data == 0) {
                        alert("添加附件失败!");
                    }
                }
            });
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <div class="editartcle" style="width:720px">
    <br />
    <h2>编辑文章</h2><br />
            <input type="text" id="titlebox" style="width:700px;height:35px;Font-Size:20pt" class="titleinput" />
        <br />
    <h2>内容</h2><br />
      <textarea id="editpanel"    class="xheditor {tools:'full',width:'580',height:'300',html5Upload:false,upLinkUrl:'../../Handles/file/saveremoteimg.aspx',upImgUrl:'../../Handles/file/upload.aspx'}" rows="10" cols="70"></textarea>
<div id="extended">
    <div>
       <input id="savebtn" type="button" class="bluebutton" value="保存" style="width:70px;height:25px;" />
        &nbsp&nbsp
        <input id="publicbtn" type="button" value="发布" style="height:25px;width:70px" class="bluebutton" />
     </div>
     <div>
     文章分类：<br />
         <div id="ClassList"></div><br />
     </div>
     <span id="showupload" style="font:14pt;color:red;">添加附件</span>
     <div id="fileupload" style="display:none">
        <input type="file" name="uploadify" id="uploadify" /> 
        <a href="javascript:$('#uploadify').uploadifyUpload()">上传</a>| 
        <a href="javascript:$('#uploadify').uploadifyClearQueue(); window.opener.unlockui("+""+")"> 取消上传</a> 
        <div id="fileQueue"></div> 
        <div id="comfile"></div>
    </div>
</div>
</div>
</asp:Content>

